<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//Dtd XHTML 1.0 Transitional//EN" "http://www.w3.org/tr/xhtml1/Dtd/xhtml1-transitional.dtd">
<html>
	<head>
		<%@include file="/WEB-INF/page/include/head.jsp"%>
		<title>登录页面</title>
	</head>
	<BODY onload="sf();" >
		<s:form method="post" action="login_login" namespace="/login" theme="simple">
			<TABLE >
				<TR>
					<TD>
						用户名：
					</TD>	
					<TD>	
						<s:textfield name="userBean.username" id="userBean.username"/> 
					</TD>
				</TR>
				<TR>
					<TD>
						密&nbsp;码：
					</TD>	
					<TD>
						<s:password name="userBean.password" id="userBean.password"/> 
					</TD>
				</TR>
				<TR>
					<TD>
						验证码：
					</TD>	
					<TD>
						<s:textfield name="sofeCode" id="sofeCode"/> 
						<img border="0" id="safecode" name="safecode" style="cursor : pointer;height:25px;weight:60px" onclick="changepic();"/>&nbsp;
					</TD>
				</TR>
				<TR>
					<TD colspan="2">
						<input type="button" value="登录" onclick="login();"/>
						<a href="javascript:void(0);" onclick="changepic();return false;">看不清</a>
					</TD>	
				</TR>
			</TABLE>
		</s:form>
	</body>
	<script type="text/javascript">
	function sf(){
	    document.getElementById("userBean.username").focus();
		changepic();
	}
	//切换验证码图片 
	function changepic(){
		var randval = Math.random();
		document.getElementById('safecode').src='<%=path%>/image.jsp?rnum=' + randval;
		//document.getElementById("safe").value = "";
	}
	//登录
	function login(){
		var username = document.getElementById("userBean.username");
		var password = document.getElementById("userBean.password");
		var sofeCode = document.getElementById("sofeCode");
		if (username.value.Trim() == '') {
			alert("名称不能为空");
			username.focus();
			return false;
		}
		if (password.value.Trim() == '') {
			alert("密码不能为空");
			password.focus();
			return false;
		}
		if (sofeCode.value.Trim() == '') {
			alert("验证码不能为空");
			sofeCode.focus();
			return false;
		}
		var url = "<%=path%>/login/login_login?userBean.username=" + username.value.Trim();
		url += "&userBean.password=" +password.value.Trim();
		url += "&sofeCode=" +sofeCode.value.Trim();
		url += "&tmp=" + Math.random();
		$.get(url,function(data){
			if(data=='1'){
				window.top.location.href="<%=path%>/manage/index.jsp";
			}else if(data=='2'){
				alert("密码错误");
				password.value='';
				password.focus();
			}else if(data=='3'){
				alert("验证码错误");
				sofeCode.value='';
				sofeCode.focus();
			}else if(data=='4'){
				alert("用户不存在");
				username.value='';
				username.focus();
			}else if(data=='5'){
				alert("用户不能为空");
				username.value='';
				username.focus();
			}else if(data=='-1'){
				alert("后台错误");
			}
		});
		
	}
</script>
</html>
